<?php

class pages
{
	public function __construct($table) {	
		$this->table = $table;
	}	
	
	public function FirstPage()
	{		
		$this->pInfo = functions::getInfoUpdate($this->table);
		
		/* Изменение порядка и проверка на удаление */
		if($_POST['subaction'] == 'updateitems') {			
			$this->confirm = functions::updateItems($_POST, $this->table, "por");
		}
		/* Удаление записей */
		elseif($_POST['id_delete']) {
			$this->confirm = functions::deleteItems($_POST, $this->table);
		}

		/* Если каталог */
		if(preg_match("/^([0-9]+)$/", $this->active_group)) {
			$SQL = "WHERE `Parent`='".$this->active_group."'";
		}
		
		$r =& Registry::get("MDB")->query("SELECT * FROM `".$this->table."` ".$SQL." ".$this->sorting.";");
		if (PEAR::isError($r)) {
			die($r->getMessage().' ::: '.$r->getUserInfo());
		}
		if($r->numRows())
		{
			while($p = $r->fetchRow(MDB2_FETCHMODE_ASSOC)) {
				if(!empty($p["name"])) {
					$p["name"] = htmlspecialchars($p["name"]);
				}				
				$ArrayField[] = $p;				
			}			
		}
		Registry::get("smarty")->assign(array(
			'CFG_FIELD'       => $this->field,
			'TBODY_TD'        => $ArrayField,
			'ACT_NAME'        => $this->section,
			'TABLE'           => $this->table,
			'MODE'            => $this->mode,
			'INFO_TABLE'      => $this->pInfo,
			'IS_ACTIVE_GROUP' => $IS_ACTIVE_GROUP,
			'ACTIVE_GROUP_ID' => $this->active_group,
			'CONFIRM'         => $this->confirm
		));		
		return Registry::get("smarty")->fetch(TEMPLATE_ADMIN.'pages.list.admin.tpl');	
	}
}

?>